package Servises;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import model.GameInfo;

public class RealSaxParser {
	
	public GameInfo parseXml(String xmlPath)
	{
		try{
			URL xmlUrl = new URL(xmlPath);
	        /* Get a SAXParser from the SAXPArserFactory. */ 
	        SAXParserFactory spf = SAXParserFactory.newInstance(); 
	        SAXParser sp = spf.newSAXParser(); 
	
	        /* Get the XMLReader of the SAXParser we created. */ 
	        XMLReader xr = sp.getXMLReader(); 
	        /* Create a new ContentHandler and apply it to the XML-Reader*/ 
	        MySaxHandler myExampleHandler = new MySaxHandler(); 
	        xr.setContentHandler(myExampleHandler); 
	         
	        /* Parse the xml-data from our URL. */ 
	        xr.parse(new InputSource(xmlUrl.openStream())); 
	        
	        return myExampleHandler.getParsedData();
		}
		catch(Exception e){
			return null;
		}
	}
}
